package com.suntoon.framework.config;

import com.suntoon.framework.interceptor.LoginInterceptor;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @Author: LEAVES
 * @Version 1.0
 * @Date: 2021年06月21日 14时37分21秒
 * @Description:    注册拦截器配置
 */
@Configuration
public class WebConfig implements WebMvcConfigurer, InitializingBean {

    @Resource
    private LoginInterceptor loginInterceptor;

    @Override
    public void afterPropertiesSet() throws Exception {

    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**");
    }

    /**
     * 文件配置
     */
//    @Bean(name = "multipartResolver")
//    public MultipartResolver multipartResolver() {
//        CommonsMultipartResolver resolver = new CommonsMultipartResolver();
//        resolver.setDefaultEncoding("UTF-8");
//        //resolveLazily属性启用是为了推迟文件解析，以在在UploadAction中捕获文件大小异常
//        resolver.setResolveLazily(true);
//        resolver.setMaxInMemorySize(40960);
//        //上传文件大小 10G
//        resolver.setMaxUploadSize(5 * 1024 * 1024 * 1024);
//        return resolver;
//    }
}
